<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class home_model extends CI_Model
{
	function __construct(){
        parent::__construct();
	}
	
	function get_all($num=30, $offset=0)
	{
		$this->db->select('raovat.*, town.town_name');
		$this->db->where('raovat.bl_active',1);
		$this->db->join('town','town.town_id=raovat.town_id', 'left') ;
		$this->db->order_by('dt_modify','DESC');
		$query = $this->db->get('raovat', $num, $offset);
		return $query->result();
	}
	
	function count_all()
	{      
		 $this->db->where('raovat.bl_active',1);
		 $this->db->join('town','town.town_id=raovat.town_id', 'left') ;
		 $query = $this->db->get('raovat');
		 return $query->num_rows();
	}

	
	function get_all_category($class_id, $num=20, $offset=0)
	{
		$this->db->select('raovat.*, town.town_name');
		$this->db->where('class_id',$class_id);	
		$this->db->where('raovat.bl_active',1);
		$this->db->join('town','town.town_id=raovat.town_id', 'left') ;	
		$this->db->order_by('dt_modify','DESC');
		$query = $this->db->get('raovat',$num, $offset);
		return $query->result() ;	
	}
	
	function count_all_category($class_id)
	{
		$this->db->where('class_id',$class_id);
		$this->db->where('raovat.bl_active',1);
		$this->db->join('town','town.town_id=raovat.town_id', 'left') ;
		$query = $this->db->get('raovat');
		return $query->num_rows();
	}
	
	function get_detail($id)
	{
		$this->db->select('raovat.*, member.username, member.address, member.lb_email, member.lb_yahoo, member.lb_website');
		$this->db->where('raovat_id',$id);
		$this->db->join('member','member.member_id=raovat.member_id') ;
		$query = $this->db->get('raovat');
		return $query->row();	
	}
	
	function get_last_news($mid, $num=20, $offset=0)
	{
		$this->db->where('bl_active',1);
		$this->db->where('mID',$mid);
		$this->db->order_by('dt_create','DESC');//'DESC'
		return $this->db->get('raovat',$num, $offset)->result();
	}
	
	function get_news_by_user($member_id, $num=20,$offset=0)
	{
		$this->db->select('raovat.*, town.town_name');
		$this->db->where('member_id',$member_id);	
		$this->db->select('raovat.*, town.town_name');
		$this->db->where('raovat.bl_active',1);
		$this->db->join('town','town.town_id=raovat.town_id', 'left') ;	
		$this->db->order_by('dt_modify','DESC');
		$query = $this->db->get('raovat',$num, $offset);
		return $query->result() ;	
	}

}
?>
